﻿Option Explicit On ' Make sure all items are explicitly declared
Option Strict On ' Be Very Strict about things here!
Namespace ZuneCardr
    ''' <summary>Playlist</summary>
    ''' <author>Comentsys</author>
    ''' <version>1.0.0</version>
    ''' <created>1st February 2009</created>
    ''' <modified>1st February 2009</modified>
    ''' <remarks>Playlist Data</remarks>
    Public Class Playlist

        ' Public Constants

        Public Const FAVS As String = "favs"
        Public Const RECENT As String = "recent_spins"
        Public Const PLAYED As String = "most_played"

        ' Private Constants

        Private Const ATTR_TYPE As String = "type"

        ' Private Members

        Private strType As String
        Private strName As String
        Private strMessage As String
        Private _Tracks As New List(Of Track) ' Tracks
        Private _Artists As New List(Of Artist) ' Tracks

        ' Private Methods

        ''' <summary>GetTracks</summary>
        ''' <param name="Elements">Track XML Elements</param>
        Private Sub GetTracks(ByRef Elements As IEnumerable(Of XElement))
            _Tracks.Clear()
            For Each Result In Elements
                _Tracks.Add(New Track(Result))
            Next
        End Sub

        ''' <summary>GetArtists</summary>
        ''' <param name="Elements">Artist XML Elements</param>
        Private Sub GetArtists(ByRef Elements As IEnumerable(Of XElement))
            _Artists.Clear()
            For Each Result In Elements
                _Artists.Add(New Artist(Result))
            Next
        End Sub

        ' Public Methods

        ''' <summary>Constructor</summary>
        ''' <param name="Element">Element to Parse</param>
        Public Sub New(ByRef Element As XElement)
            strType = Element.Attribute(ATTR_TYPE).Value
            strName = Element.<label>.Value
            strMessage = Element.<message>.Value
            GetTracks(Element.<track>) ' Get Tracks
            GetArtists(Element.<artist>) ' Get Artists
        End Sub

        ' Public Properties

        ''' <summary>Type</summary>
        ''' <returns>Type Text</returns>
        Public ReadOnly Property Type() As String
            Get
                Return strType
            End Get
        End Property

        ''' <summary>Message</summary>
        ''' <returns>Message Text</returns>
        Public ReadOnly Property Message() As String
            Get
                Return strMessage
            End Get
        End Property

        ''' <summary>Name</summary>
        ''' <returns>Name Text</returns>
        Public ReadOnly Property Name() As String
            Get
                Return strName
            End Get
        End Property

        ''' <summary>Tracks</summary>
        ''' <returns>List of Tracks</returns>
        Public ReadOnly Property Tracks() As List(Of Track)
            Get
                Return _Tracks
            End Get
        End Property

        ''' <summary>Artists</summary>
        ''' <returns>List of Artists</returns>
        Public ReadOnly Property Artists() As List(Of Artist)
            Get
                Return _Artists
            End Get
        End Property

    End Class
End Namespace
